/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef M_LOG_H
#define M_LOG_H

#include "singleton.h"

#include <string>
#include <sstream>
#include <fstream>
#include <time.h>

namespace Engine
{
	/**
	*   String stream based log system.
	*/
	class Log: public Singleton<Log>
	{
	public:
		/**
		*   Constructor. Init date time stamp.
		*/
		Log();

		/**
		*   Write long strings to file;
		*/
		void WriteToFile(const std::string& fileName)const;

		/**
		*   Delegate call to string stream.
		*   Used for threads synchronization.
		*/
		template<class T>
		Log& operator << (const T& val)
		{
			Lock lock;
			m_buffer << val;
			return *this;
		}

		/**
		*   Delegate call to string stream.
		*   Used for threads synchronization.
		*/
		Log& operator << (std::ostream &(*fp)(std::ostream &))
		{
			Lock lock;
			(*fp)(m_buffer);
			return *this;
		}
	private:
		std::string m_timestr;
		std::stringstream m_buffer;
	};
}

#endif

